import { Controller, Get, Query } from '@nestjs/common';
import { ForecostService } from './forecost.service';
import { Result } from '../../common/result/Result';
import { ForecostController } from './forecost.controller';
import { DictService } from '../06_dict/dict.service';

@Controller('/api/v1/forecast/ai')
export class AIForecostController {
  constructor(
    private readonly forecostService: ForecostService,
    private readonly dictService: DictService,
  ) {}

  @Get('/calculate')
  async calculateAll(
    @Query('itemMaster') itemMaster: string,
    @Query('org') org: string,
    @Query('code') code: string,
  ) {
    const SupplierCode = await this.getSupplierCode('Supplier');
    const result = await this.forecostService.totalCalculate(
      org,
      code,
      itemMaster,
      SupplierCode,
    );
    return Result.success(result);
  }
  async getSupplierCode(dicCode: string) {
    const dicResult = await this.dictService.dictOptions(dicCode);
    let SupplierCode = '';
    if (dicResult.data.length > 0) {
      SupplierCode = dicResult.data.map((item) => `'${item.value}'`).join(',');
    }
    return SupplierCode;
  }
}
